package app.ui;

import java.awt.Color;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JTextField;

import app.action.AppUtilities;
import app.action.StartScrAct;

public class StartScr extends AbsCommonPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2787646917922111468L;

	protected JTextField jTextField; // show address
	protected JButton jButton; // browse...
	protected String[] strLabels = { "Browse..." };
	protected StartScrAct startScrAct; // action

	public StartScr(MainFrame mFrame) {
		super(mFrame);

		this.setBackground(Color.BLACK);
	}

	@Override
	protected void addComponents() {
		this.jTextField = new JTextField();
		this.jButton = new JButton(getStrLabels()[0]);

		add(jTextField);
		add(jButton);
	}

	@Override
	protected void initializeComponents() {
		// button browse
		this.startScrAct = new StartScrAct(this);
		jButton.addActionListener(startScrAct);
		// jTextField
		jTextField.setText(mFrame.getAppUtilities().getLastLocation());
	}

	@Override
	protected void resizeComponents() {
		int width = (int) (getWidth() - 1.5 * btnWid);
		int height = btnHei;
		int x = 10;
		int y = (getHeight() - height) / 3;

		// jTextField
		jTextField.setBounds(x, y, width, height);
		// jButton
		x += width + 4;
		width = btnWid;
		jButton.setBounds(x, y, width, height);
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public JTextField getjTextField() {
		return jTextField;
	}

	public JButton getjButton() {
		return jButton;
	}

	public String[] getStrLabels() {
		return strLabels;
	}

	public StartScrAct getStartScrAct() {
		return startScrAct;
	}

	public void addressIsSet(File file) {
		if(file.isFile()) {
			file = file.getParentFile();
		}

		String path = file.getPath();
		getjTextField().setText(path);

		// store to property file
		mFrame.getAppUtilities().getProp().setProperty(AppUtilities.LAST_LOCATION, path);

		// get list files
		mFrame.getAppUtilities().setFiles(file);

		// show the work screen
		this.close(false);
		((MainFrame) mFrame).getWorkScr().open();
	}

}
